<template>
  <page-header-wrapper>
    <a-spin :spinning="loading" tip="加载中...">
      <div class="iframe-box">
        <a-space>
          <a-button type="primary" icon="download" @click="handleDownload('html')">下载HTML文档</a-button>
          <a-button type="primary" icon="download" @click="handleDownload('doc')">下载Word文档</a-button>
          <a-button type="primary" icon="download" @click="handleDownload('md')">下载Markdown文档</a-button>
        </a-space>
      </div>
      <div class="iframe-box" :style="'height:'+ height">
        <iframe :src="src" frameborder="no" style="width: 100%; height: 100%" scrolling="auto"/>
      </div>
    </a-spin>
  </page-header-wrapper>
</template>

<script>

import {downloadDataBase} from '@/api/generate/dataBaseDoc'

export default {
  data() {
    return {
      src: process.env.VUE_APP_BASE_API + '/generate/dataBaseDoc/preview',
      height: document.documentElement.clientHeight - (64 + 40 + 49 + 20 + 260) + 'px;',
      loading: true
    }
  },
  mounted() {
    setTimeout(() => {
      this.loading = false
    }, 230)
    const that = this
    window.onresize = function temp() {
      that.height = document.documentElement.clientHeight - (64 + 40 + 49 + 20 + 260) + 'px;'
    }
  },
  methods: {
    handleDownload(type) {
      downloadDataBase({type: type}).then(res => {
        this.$message.success(res.msg)
      })
    }
  }
}
</script>
<style scoped>
.iframe-box:first-child {
  padding: 20px;
  text-align: center;
}

.iframe-box {
  margin: auto;
  background-color: white;
}
</style>
